import 'package:flutter/material.dart';
import 'package:kq_flutter_core_widget/utils/kq_screen_util.dart';
import '../theme/kq_theme_manager.dart';
import '../widgets/button/kq_underline_button.dart';

class AttachMentUtil {
  //需要嵌套CustomScrollView
  static Widget renderItem({
    required int totalCount,
    required String Function(int index)? renderTitleCallback,
    Function(int index)? onTap,
    double? top, //最顶部的间隙 默认6.r
    double? endBottom, //最后一条的间隙 默认跟随系统 15.r
  }) {
    return SliverList(
      delegate: SliverChildBuilderDelegate((_, int index) {
        String? txt = renderTitleCallback!(index);
        double hor =
            KqThemeManager.instance.getConfig().formConfig.paddingHorizontal ??
                16.r;
        double bottom = totalCount == index + 1
            ? endBottom ??
                KqThemeManager.instance
                    .getConfig()
                    .formConfig
                    .paddingVertical ??
                15.r
            : top ?? 6.r;
        return Container(
          padding: EdgeInsets.only(
              left: hor, right: hor, top: top ?? 6.r, bottom: bottom),
          child: KqUnderlineButton(
            title: txt,
            textAlign: TextAlign.start,
            onTap: () {
              if (onTap != null) {
                onTap(index);
              }
            },
          ),
        );
      }, childCount: totalCount),
    );
  }
}
